package com.zq.springadmin.controller;


import com.zq.springadmin.dao.entity.Permission;
import com.zq.springadmin.logs.sysLogs;
import com.zq.springadmin.service.IPermissionService;
import com.zq.springadmin.util.Result;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 张乔
 * @Date 2024/5/21 21:41
 */
@RestController
@RequestMapping("/sys/menu")
@Slf4j
public class MenuController {


    @Resource
    private IPermissionService permissionService;

//    获取所有菜单
    @GetMapping("/getAll")
    public Result<List<Permission>> getAll() {
        List<Permission> permissionList=permissionService.getAll();
        log.info("获取所有菜单成功"+ permissionList.get(0));
return Result.successData(permissionList);

    }

//增加菜单
@PostMapping("/save")
@sysLogs(title = "菜单管理：新增一级菜单",businessType = 1)

public Result<String> save(@RequestBody Permission permission) {
    permissionService.saveMenu(permission);
    log.info("增加菜单成功"+ permission);
    return Result.success();
}


//    跟据id修改菜单
@PutMapping("/updateById")
@sysLogs(title = "菜单管理：修改菜单",businessType = 1)

public Result<String> updateById(@RequestBody Permission permission) {
    permissionService.updateById(permission);
    return Result.success();
}

//    删除菜单

    @DeleteMapping("/removeById/{id}")
    @sysLogs(title = "菜单管理：删除菜单",businessType = 1)

    public Result<String> removeById(@PathVariable Integer id) {
        permissionService.removeByIdApi(id);
        return Result.success();
    }







}
